﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Studio77.GuessTheWords2.Views;
using Coding4Fun.Phone.Controls;
using System.Windows.Media.Imaging;
using Studio77.GuessTheWords2.Core;

namespace Studio77.GuessTheWords2.Pages
{
    public partial class ClassifyPage : PhoneApplicationPage
    {
        public static ClassifyPage Instance = null;

        public ClassifyPage()
        {
            InitializeComponent();
            Instance = this;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            //检查是否能够解锁章节
            int cIndex = StageManager.Instance.JudgeClassUnlock();
            if (cIndex > 0)
            {
                ShowToast("恭喜您成功解锁了第" + cIndex + "章节，快去试试吧！");
                UmengSDK.UmengAnalytics.TrackEvent("classunlock", cIndex.ToString());
            }

            foreach (var item in this.grid.Children)
            {
                if (item is ClassifyItem)
                {
                    (item as ClassifyItem).ShowContent();
                }
            }


        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        /// <param name="message"></param>
        public static void ShowToast(String message)
        {
            ShowToast("提示", message, null);
        }

        /// <summary>
        /// 显示提示信息
        /// </summary>
        public static void ShowToast(String title, String message, BitmapImage icon)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                ToastPrompt toast = new ToastPrompt();
                toast.Title = title;
                toast.Message = message;
                toast.TextOrientation = System.Windows.Controls.Orientation.Horizontal;
                toast.ImageSource = icon;
                toast.Show();
            });
        }
    }
}